/*
 * @lc app=leetcode.cn id=434 lang=cpp
 *
 * [434] 字符串中的单词数
 */

// @lc code=start
class Solution
{
public:
  int countSegments(string s)
  {
    int start = 0, n = s.size();
    int ans = 0;
    while (start < n) {
      while (start < n && s[start] == ' ')
        ++start;
      int end = start;
      while (end < n && s[end] != ' ')
        ++end;
      if (end - start > 0)
        ++ans;
      start = end;
    }
    return ans;
  }
};
// @lc code=end
